#include <cstdio>

const int N = 100005;
int t, m, q, mod, opt;
int val[N << 2];

inline void pushup(int x) { val[x] = 1ll * val[x << 1] * val[x << 1 | 1] % mod; }

void modify(int x, int l, int r, int pos, int v) {
  if (l == r) {
    val[x] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify(x << 1, l, mid, pos, v);
  else
    modify(x << 1 | 1, mid + 1, r, pos, v);
  pushup(x);
}

long long query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return val[x];
  }
  int mid = (l + r) >> 1;
  long long res = 1;
  if (L <= mid) (res *= (long long)query(x << 1, l, mid, L, R)) %= mod;
  if (mid < R) (res *= (long long)query(x << 1 | 1, mid + 1, r, L, R)) %= mod;
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("P4588 [TJOI2018]数学计算.in", "r", stdin);
  freopen("P4588 [TJOI2018]数学计算.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &q, &mod);
    for (int i = 1; i <= q; ++i) {
      scanf("%d", &opt);
      if (opt == 1) {
        scanf("%d", &m);
        modify(1, 1, q, i, m);
        printf("%lld\n", query(1, 1, q, 1, i));
      } else {
        scanf("%d", &m);
        modify(1, 1, q, i, 1);
        modify(1, 1, q, m, 1);
        printf("%lld\n", query(1, 1, q, 1, i));
      }
    }
  }
  return 0;
}